package com.wantupai.mvp.framework.lce.impl.activity;

import android.view.View;

import com.wantupai.mvp.framework.lce.ILceAnimator;
import com.wantupai.mvp.framework.lce.MvpLceView;
import com.wantupai.mvp.framework.lce.impl.MvpLceViewImpl;
import com.wantupai.mvp.mvp.MvpPresenter;
import com.wantupai.mvp.mvp.MvpView;
import com.wantupai.mvp.mvp.lce.activity.MvpActivity;


/**
 * @param <D>
 * @param <V>
 * @param <P>
 * @author zhangqing
 * 代理模式->代理对象
 */
public class MvpLceActivity<D, V extends MvpView<D>, P extends MvpPresenter<V>> extends MvpActivity<D, V, P> implements MvpLceView<D>
{


    @Override
    public MvpLceViewImpl<D> getMvpLceView()
    {
        if (mDMvpViewImpl == null)
        {
            mDMvpViewImpl = new MvpLceViewImpl<D>();
        }
        return (MvpLceViewImpl) mDMvpViewImpl;
    }

    @Override
    public void refreshComplete()
    {

    }

    /**
     * LCE加载
     */
    @Override
    public void onContentChanged()
    {
        super.onContentChanged();
        getMvpLceView().initView(getWindow().getDecorView().findViewById(android.R.id.content));
        getMvpLceView().setOnClickErrorListener(this::onErrorClick);
    }

    @Override
    public void onErrorClick(View v)
    {
        //重新加载
        loadData(false);
    }

    public void setLceAnimator(ILceAnimator animator)
    {
        getMvpLceView().setAnimator(animator);
    }

    @Override
    public void loadData(boolean isPullToRefresh)
    {
        getMvpLceView().loadData(isPullToRefresh);
    }

    @Override
    public void showLoading(boolean isPullToRefresh)
    {
        getMvpLceView().showLoading(isPullToRefresh);
    }


    @Override
    public void noMoreData()
    {
        getMvpLceView().noMoreData();
    }

    @Override
    public void loadMoreError()
    {
        getMvpLceView().loadMoreError();
    }

    @Override
    public void loadRefreshError()
    {
        getMvpLceView().loadRefreshError();
    }

}
